/**
 * 图纸上传接口
 * todo: 校验文件格式
 */

import { Request, Response, NextFunction } from 'express'
import { toFail, toLogin, useUploadRoot, useUser } from './utils'
export default async (req: Request, res: Response, next: NextFunction) => {
    const file = req.file;
    if (!file) {
        return res.json(toFail('No file uploaded.'));
    }
    const filePath = file.path;
    const root = useUploadRoot(req);
    const url = filePath.replace(root, '')
    return res.json({ url, uid: url, success: true, filename: file.filename })
}
